package com.example.download.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.example.download.R
import androidx.recyclerview.widget.RecyclerView
import com.example.download.bean.home_item

class home_itemAdapter(private val homeitemList: List<home_item>) : RecyclerView.Adapter<home_itemAdapter.ViewHolder>(){
    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val iv_hi_imageURL: ImageView = view.findViewById(R.id.iv_hi_imageURL)
        val tv_hi_title: TextView = view.findViewById(R.id.tv_hi_title)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.home_item, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = homeitemList[position]
        holder.iv_hi_imageURL.setImageResource(item.iv_hi_imageURL?.toInt()?: 0)
        holder.tv_hi_title.text = item.tv_hi_title
    }

    override fun getItemCount(): Int {
        return homeitemList.size
    }
}